package u.can.i.up.utils;

import java.io.File;

import brut.androlib.AndrolibException;
import brut.androlib.res.data.ResPackage;
import brut.androlib.res.data.ResTable;
import brut.androlib.res.decoder.ARSCDecoder;
import brut.androlib.res.util.ExtFile;
import brut.directory.DirectoryException;

public class ApkUtil {

	public static String getPackageNameByApkPath(String filePath) {
		String packageName = null;
		ResTable resTable = new ResTable();
		ResPackage[] resPackages;
		try {
			resPackages = ARSCDecoder
					.decode(new ExtFile(new File(filePath)).getDirectory().getFileInput("resources.arsc"), false, false,
							resTable)
					.getPackages();
			packageName = resPackages[0].getName();
		} catch (AndrolibException | DirectoryException e) {
			e.printStackTrace();
		}
		return packageName;
	}
}
